package com.todod.base.module.base.dal.mysql.rthistory;

import java.time.LocalDateTime;
import java.util.*;

import com.todod.base.framework.common.pojo.PageResult;
import com.todod.base.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.todod.base.framework.mybatis.core.mapper.BaseMapperX;
import com.todod.base.module.base.dal.dataobject.rthistory.RtHistoryDO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import com.todod.base.module.base.controller.admin.rthistory.vo.*;
import org.apache.ibatis.annotations.Select;

/**
 * 历史数据管理 Mapper
 *
 * @author 超管儿
 */
@Mapper
public interface RtHistoryMapper extends BaseMapperX<RtHistoryDO> {

    default PageResult<RtHistoryDO> selectPage(RtHistoryPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<RtHistoryDO>()
                .betweenIfPresent(RtHistoryDO::getReceivetime, reqVO.getReceivetime())
                .betweenIfPresent(RtHistoryDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(RtHistoryDO::getId));
    }



    /**
     * 创建备份表
     */
    @Select("CREATE TABLE ${backupTable} LIKE ${table};")
    void createBackupTable(String backupTable, String table);

    /**
     * 插入数据到备份表
     */
    @Select("INSERT INTO ${backupTable} SELECT * FROM ${table};")
    void insertIntoBackupTable(String backupTable, String table);


    /**
     * 物理删除所有数据表数据
     */
    @Select("TRUNCATE TABLE base_rt_history ")
    public void cleanAll();


    /**
     * 根据年份物理删除数据表数据
     */
    @Delete("DELETE FROM base_rt_history WHERE YEAR(receivetime) = #{year}")
    public void deleteByYear(String year);

}